package huoye.shops.base;

import com.codeideology.android.AXIUserManager;
import com.codeideology.android.utils.StringUtils;

import huoye.shops.huoye.user.model.User;
import huoye.shops.sp.UserManagerHelper;


/**
 * Created by user on 2016/11/23.
 */

public class UserManager extends UserManagerHelper {

    private static UserManager instance;
    public static UserManager getInstance() {
        if(instance == null) {
            instance = new UserManager();
        }
        return instance;
    }

    @Override
    public boolean isLogin() {
        return user != null;
    }

    private boolean isLogin;

    public void setLogin() {
        isLogin = true;
    }

    private UserManager() {

    }
    @Override
    public void logout() {
        user = null;
        removeUserId();
        removeUsername();
        removePassword();
        removeUserShopId();
        removeAngentId();
        removeShopLogo();
        removeWithdrawAccount();
        removeOverdue();
        removePowerManage();
    }


    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
        saveUserId(user.getId());
        saveUserId(user.getUserId());
        saveUserShopId(user.getShopId());
        saveShopLogo(user.getUserImg());
        saveCardType(user.getiCardType());
        saveAngentId(user.getAngentId());
        saveOverdue(user.isOverdue());
        savePowerManage(user.isPowerManage());

    }


    public String getUid() {
        String id = getUserId();
        if(StringUtils.isEmpty(id)) {
            return "0";
        }else {
           return id;
        }
    }






    public void setDeviceHash(String deviceHash) {
        this.deviceHash = deviceHash;
    }

    public String getDeviceHash() {
        return deviceHash;
    }

    private String deviceHash;



}
